﻿using SqlSugar;
using System;  
using System.Configuration;

namespace FamilyTree.DLL
{
    public class WebDataAccess
    {
        protected string domain = "http://localhost:5000/api/";
        protected string DBConnectStr = "server=127.0.0.1;port=3306;uid=root;pwd=123456;database=huahua_mes";

        public SqlSugarClient SugarClient = null;

        public WebDataAccess()
        { 
            //domain = ConfigJsonRead.GetValue("Domain");  //ConfigJsonRead.GetValue("Domain"); //configuration.Read("Domain");
            DBConnectStr = ConfigurationManager.ConnectionStrings["SQLiteConnection"].ConnectionString;

            //创建数据库对象 (用法和EF Dappper一样通过new保证线程安全)
            SugarClient = new SqlSugarClient(new ConnectionConfig()
            {
                ConnectionString = DBConnectStr,
                DbType = DbType.Sqlite,
                InitKeyType = InitKeyType.Attribute,//从特性读取主键和自增列信息
                IsAutoCloseConnection = true,//开启自动释放模式   自动关闭数据库连接
            },
            db => {

                db.Aop.OnLogExecuting = (sql, pars) =>
                {
                    //获取原生SQL推荐 5.1.4.63  性能OK
                    Console.WriteLine(UtilMethods.GetNativeSql(sql, pars));
                };

            });

        }



    }
}
